package com.cs.redis.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RedisPropertyUtil {

	  private final Logger logger = LoggerFactory.getLogger(RedisPropertyUtil.class);
	  private Properties props;
	  private String _fileName;
	  
	  public RedisPropertyUtil(String fileName)
	  {
		  _fileName = fileName;
	  }

	  synchronized private void loadProps() {
	    logger.info("start to load MybaitsPropertyUtil2 "+_fileName+"properties.......");
	    props = new Properties();
	    InputStream in = null;
	    try {

	      in = RedisPropertyUtil.class.getClassLoader().
	      getResourceAsStream(_fileName);
	      props.load(in);
	      logger.info("application.properties");
	    } catch (FileNotFoundException e) {
	      logger.error("properties not found!");
	    } catch (IOException e) {
	      logger.error("IOException");
	    } finally {
	      try {
	        if (null != in) {
	          in.close();
	        }
	      } catch (IOException e) {
	        logger.error("properties close Exception!");
	      }
	    }
	    // logger.info(props);
	    logger.info("load properties over...........");
	  }

	  public String getProperty(String key) {
	    if (null == props) {
	      loadProps();
	    }
	    return props.getProperty(key);
	  }
}